package com.ygsoft.nio.fileserver;

import java.nio.ByteBuffer;
import java.io.*;

public class DataController {
	
	private int state = 0;
	
	public DataController(){
		this.state = 0;
		System.out.println("DataController Active..");
	}
	
	public void processData(ByteBuffer readBuffer){
		System.out.println();
		if(this.state == 0){
			byte[] buf = new byte[8];
			readBuffer.get(buf, 0, buf.length);
			DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf));
			long fileSize = -1;
			try {
				fileSize = dis.readLong();
				dis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
//			for(int i=0;i<buf.length;i++){
//				System.out.println(i + ">" + buf[i]);
//			}
			
			System.out.println("File Size >" + fileSize);
			
			try {
				Thread.sleep(4000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			this.state = 1;
		} else if(this.state == 1){
			System.out.println("Read File..");
		} else {
			;
		}
	}
}
